"use strict";

(function () {
  function r(e, n, t) {
    function o(i, f) {
      if (!n[i]) {
        if (!e[i]) {
          var c = "function" == typeof require && require;
          if (!f && c) return c(i, !0);
          if (u) return u(i, !0);
          var a = new Error("Cannot find module '" + i + "'");
          throw a.code = "MODULE_NOT_FOUND", a;
        }

        var p = n[i] = {
          exports: {}
        };
        e[i][0].call(p.exports, function (r) {
          var n = e[i][1][r];
          return o(n || r);
        }, p, p.exports, r, e, n, t);
      }

      return n[i].exports;
    }

    for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
      o(t[i]);
    }

    return o;
  }

  return r;
})()({
  1: [function (require, module, exports) {
    "use strict";

    loader.define(function (require, exports, module, global) {
      var pageview = {};

      pageview.init = function () {
        // $('.detail-panel').hide();
        $('.btn-close').on('click', function (e) {
          $('.detail-panel').hide();
        });
        var lng, lat, address, uid, currentp;
        var getParams = bui.getPageParams();
        getParams.done(function (result) {
          lng = result['lng'];
          lat = result['lat'];
          address = result['address'];
          uid = result['uid'];
        });
        var map = new BMap.Map("map");
        var point = new BMap.Point(lng, lat);
        map.centerAndZoom(point, 15);
        map.enableScrollWheelZoom(true);
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function (r) {
          if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var currentp = r.point;
            var options = {
              onSearchComplete: function onSearchComplete(results) {
                var pos = undefined;

                if (local.getStatus() == BMAP_STATUS_SUCCESS) {
                  // 判断状态是否正确         
                  for (var i = 0; i < results.getCurrentNumPois(); i++) {
                    // console.log(results.getPoi(i));
                    var t = results.getPoi(i);

                    if (t.uid == uid) {
                      pos = t;
                      break;
                    }
                  }

                  if (pos == undefined) {
                    pos = results.getPoi(0);
                  } // console.log(pos);
                  // // 取到相关信息
                  // console.log(currentp);


                  var dis = map.getDistance(currentp, pos.point); // console.log(dis);

                  $("#adname").text(pos.title);
                  $("#adroad").text(pos.address);
                  $("#addis").text('距离您' + parseInt(dis) + '米'); // 画点

                  var marker = new BMap.Marker(pos.point);
                  var icon = marker.getIcon(); // console.log(icon.size);

                  icon.setSize(new BMap.Size(76, 100));
                  marker.setIcon(icon);
                  marker.addEventListener('click', function () {
                    var display = $('.detail-panel').css('display');

                    if (display == 'none') {
                      $('.detail-panel').show();
                    } else {
                      $('.detail-panel').hide();
                    }
                  });
                  map.addOverlay(marker);
                }
              }
            };
            var local = new BMap.LocalSearch(map, options);
            local.search(address);
          } else {
            // alert('failed'+this.getStatus());
            bui.hint({
              content: "<i class='icon-error'></i><br />请检查是否开启GPS",
              position: "center",
              effect: "fadeInDown"
            });
          }
        }, {
          enableHighAccuracy: true
        }); // navigator.geolocation.getCurrentPosition(function(position) {
        //     //得到html5定位结果
        //     var plat, plng;
        //     plng = position.coords.longitude;
        //     plat = position.coords.latitude;
        //     currentp = new BMap.Point(plng, plat);
        // }, function (err) { 
        //     console.log(err.code);
        // }, {
        //     enableHighAcuracy: true
        // });
      };

      pageview.init();
      return pageview;
    });
  }, {}]
}, {}, [1]);